﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LoginTest
{
    public partial class ToolStrip : Form
    {
        public ToolStrip()
        {
            InitializeComponent();
        }

        private void ToolStrip_Load(object sender, EventArgs e)
        {
            this.Text = "样本管理";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int count = 0;
            try
            {
                count = Convert.ToInt32(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("单价输入不合法");
                return;
            }
            if (comboBox1.SelectedIndex == -1 || count <= 0)
            {
                MessageBox.Show("请输入样本号");
            }
            else
            {
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    //这里问题
                    if (comboBox1.GetItemText(comboBox1.SelectedItem).ToString().Equals(dataGridView1.Rows[i].Cells[0].Value.ToString()))
                    {
                        Console.WriteLine(comboBox1.GetItemText(comboBox1.SelectedItem).ToString().Equals(dataGridView1.Rows[i].Cells[0].Value.ToString()));
                        Console.WriteLine(comboBox1.GetItemText(comboBox1.SelectedItem).ToString());
                        Console.WriteLine(dataGridView1.Rows[i].Cells[0].Value.ToString());
                        int oldCount = Convert.ToInt16(dataGridView1.Rows[i].Cells[1].Value.ToString());
                        dataGridView1.Rows[i].Cells[1].Value = oldCount + count;
                        return;
                    }
                }
                dataGridView1.Rows.Add(comboBox1.GetItemText(comboBox1.SelectedItem), count);
            }
        }
    }
}
